package antGraph;

import graph.Edge;
import graph.Vertex;

/*
 * authors: Clayson Celes and Andrey Bicalho
 */
public class AntEdge extends Edge {

	private double updateQuantity;

	public static final double EVAPORATION_COEFFICIENT = 0.3; // search value 
	
	private static double saturationLevel = Long.MAX_VALUE;
	
	public AntEdge(Vertex node1, Vertex node2) {
		super(node1, node2, 1); // the initial cost value is 1
	}

	public AntEdge(Vertex node1, Vertex node2, double cost) {
		super(node1, node2, cost);
	}

	public void addPheromone(double pheromone) {
		updateQuantity += pheromone;
	}

	public static void setMaxSaturation(double saturationLevel) {
		AntEdge.saturationLevel = saturationLevel;
	}

	public void updatePheromone() {
		if (getNode1() instanceof AntVertex	&& getNode2() instanceof AntVertex) {
			AntVertex antVertex1 = (AntVertex) getNode1();
			AntVertex antVertex2 = (AntVertex) getNode2();
			if (antVertex1.hasFood() || antVertex2.hasFood()) {
				updateQuantity = 0;
				setCost(Double.MAX_VALUE);
				return;
			}
		}

		double nextLevel = (1 - EVAPORATION_COEFFICIENT) * getCost();
		double cost = Math.max(1, nextLevel) + updateQuantity;
		cost = Math.min(saturationLevel, cost);
		setCost(cost);
		updateQuantity = 0;

	}
}
